<!DOCTYPE html>
<html lang="zh-CN">
<head>
 
<#include "bases/global_style.ftl">
<#include "bases/global_js.ftl">
<#include "bases/combo.ftl">
 
	    
    <script>
        var curent_page=${currentpage};
 
   
        var dataform;
        jQuery(document).ready(function()
        {
            var optInit = getOptionsFromForm();
            $("#Pagination").pagination(${totalRecord}, optInit);
            App.init();
            combox("provinceid","Province",null,null,false);
            combox('cityid','City',$("#provinceid").val(),null,false);
            combox('areaid','Area',$("#cityid").val(),null,false);
            dataform=$("#dataform").validate();
        });
 
        function doTableSort(ID)
        {
            $("#postsortfield").val(ID);
            $("#currentpage").val(0);
            $("#searchform").submit();
        }
        
        
        function addEntity(){
      	    
        	    dataform.form();
        	    if(dataform.valid()){
	                var a ;
	                var nowtime = new Date();
	                var strtemp = ""+nowtime.getHours()+nowtime.getMinutes()+nowtime.getSeconds()+nowtime.getMilliseconds();
	                a=strtemp;

	                $("#loading").showLoading(); 
	        		$.ajax({  
		      		      type : "POST",  
		      		      url :  "${base}/add_electric_charging_site/" + a+"?"+$("#dataform").serialize(),
		      		      dataType : "json",  
		      		      success : function(data) {  
		      		       	    $('#loading').hideLoading();
			      		        if(data.result ==true) {
				      		          jAlert("操作成功！","提示", function() {
				                            window.location.reload();
					      		      });
		                        }else{
		                        	jAlert(data.msg);
		                        	
		                        }
		                        	
		      		      }  
	      		    }); 
	                
        	    }

        }
        
        function showAddDiv(){
        	
        	 $("#poppic").attr("class","fa fa-plus");
    		 $("#popname").html("新增网点");
    		 $("#dataform #name").attr("data-rule-remote","${base}/checkNameUnique?category=ElectricChargingSite&where=and del=0");
             resetForm();
        	 showPopup('formDiv');
        }
         
        function showEditDiv(id){
        	
          $("#loading").showLoading(); 	
       	  $("#poppic").attr("class","fa fa-plus");
   	 	  $("#popname").html("编辑网点");
        
      	  
          $.ajax({  
      	        type : "POST",  
      	        url : CONTEXT+'/get_electric_charging_site_by_id?id='+id,  
      	        dataType : "json",  
      	        success : function(data) {  
      	      	    $("#dataform #editId").val(data.id);
     	        	$("#dataform #provinceid option[value='"+data.provinceid+"']").prop("selected", "selected");  
        	        $("#dataform #provinceid").trigger("change");
      	        	$("#dataform #cityid option[value='"+data.cityid+"']").prop("selected", "selected");  
        	        $("#dataform #cityid").trigger("change");
      	        	$("#dataform #areaid option[value='"+data.areaid+"']").prop("selected", "selected");  
      	            $("#dataform #proper_companyid option[value='"+data.proper_companyid+"']").prop("selected", "selected");  
	      	        $("#dataform #address").val(data.address);
	      	        $("#dataform #channel_num").val(data.channel_num);
	      	        $("#dataform #name").val(data.name);
	      	        $("#dataform #tel").val(data.tel);
	      	        $("#dataform input[name='supersite']").each(function () {
	                    if ($(this).val() == data.supersite) {
	                        $(this).attr("checked",true);
	                    }
	                });
	      	        $("#dataform [name = supersite]:checkbox").attr("checked", true);
	      	        $("#dataform #beginTime").val(data.beginTime);
	     	        $("#dataform #endTime").val(data.endTime);
	     	        $("#dataform #name").attr("data-rule-remote","${base}/checkNameUnique?category=ElectricChargingSite&where=and del=0 and id!="+data.id);
	     	        $('#loading').hideLoading();
		      	    showPopup('formDiv');
      	        
      	        }  
      	    }); 
        	
        }
        
        function  updateEntity(){
        	
	    	
	   	     dataform.form();
	   	     if(dataform.valid()){
	   	    	 $("#loading").showLoading(); 
	             $.ajax({  
	       	        type : "POST",  
	       	        url : CONTEXT+'/edit_electric_charging_site',  
	       	        data:$("#dataform").serialize(),
	       	        dataType : "json",  
	       	        success : function(data) {  
		       	           $('#loading').hideLoading();
		       	        	if(data.result==true){
		                        window.location.reload();
		       	        	}else{
		       	        		jAlert(data.msg);
		       	        	}
	       	        }  
	       	    }); 
	   	     }
        }
        
        function changeState(state,id){
 
        	$("#changeStatusform :radio[name='state'][value='" + state + "']").prop("checked", "checked");
            showPopup('changeStateDiv');
            $("#changeStatusform").attr("action",CONTEXT+'/change_state?id='+id);
    
        }
        
    	function showPopup(div) 
        {//弹出层
            var backDiv = document.getElementById("backDiv");
            backDiv.style.top = "0%";//设置弹出层距离上边界的距离
            backDiv.style.left = "0%";//设置弹出层距离左边界的距离
            backDiv.style.width = "100%";//设置弹出层的宽度
            backDiv.style.height = "100%";//设置弹出层的高度
            backDiv.style.visibility = "visible";

            var formDiv = document.getElementById(div);
            formDiv.style.top = "10%";//设置弹出层距离上边界的距离
            formDiv.style.left = "30%";//设置弹出层距离左边界的距离
            formDiv.style.width = "40%";//设置弹出层的宽度
            formDiv.style.height = "auto";//设置弹出层的高度
            formDiv.style.visibility = "visible";
        }
        	     
        	     
        function submitFormdata(){
        	
        	 var editId=$("#editId").val();
        	 if (editId != null && editId != "") {
        	     updateEntity();
             }else{
            	 addEntity();
             }
        }
  
 
        function hidePopup() 
        {//关闭层
  
            var formDiv = document.getElementById("formDiv");
            formDiv.style.visibility = "hidden";
   
        	
            var backDiv = document.getElementById("backDiv");
            backDiv.style.visibility = "hidden";
 
            var changeStateDiv = document.getElementById("changeStateDiv");
            changeStateDiv.style.visibility = "hidden";
            
        }
   
       function resetForm(){
    	    $("#dataform input").not(":button, :submit, :reset, :checked").val("");
	       	$("#dataform input[type=reset]").trigger("click");
	        //$("#dataform input[type=checkbox]").eq(0).attr("checked",'true');
	  	    $("#dataform #cityid").empty();
    	    $("#dataform #areaid").empty();
	     	 dataform.resetForm();
       }
    </script>
  
</head>

<body>

<div id="backDiv" onclick="hidePopup()" style="position: absolute;visibility: hidden;position:fixed;overflow: hidden;solid: #000000;background-color: #000000;padding: 1px;z-index: 99;filter:alpha(opacity=50);opacity: 0.5;"></div>

<div id="formDiv" class="row-fluid" style="position: absolute;visibility: hidden;overflow: hidden;padding: 1px;z-index: 100;background-color: #FFFFFF;">
    <div class="span12">
        <div class="portlet box green" style="padding: 0px;margin:0px;">
            <div class="portlet-title">
                <div class="caption"><i class="fa fa-edit" id="poppic"></i><span id="popname">新增网点</span></div>
                <a href="javascript:allDivHide();" class="remove"></a>
            </div>

            <div class="portlet-body flip-scroll">
                <form id="dataform"   action="<@spring.url '/edit_electric_charging_site'></@spring.url>">
                    <table class="table-bordered table-striped table-condensed flip-content">
                        <tbody role="alert" aria-live="polite" aria-relevant="all">
                      
                         <tr class="even">
                            <td style="text-align: right;">省<span class="fill-must">*</span></td>
                            <td class="even">
		                            <div class="m-wrap span8 sheet-selectTwoBar">
								        <select class="form-control" id="provinceid"  name="provinceid" onchange="combox('cityid','City',$(this).val(),null,false)" required>
										</select>
								    </div>
								 
                            </td>
                            <td style="text-align: right;">市<span class="fill-must">*</span></td>
                            <td class="even">
		                            <div class="m-wrap span8 sheet-selectTwoBar">
									    <select class="form-control" id="cityid" name="cityid" onchange="combox('areaid','Area',$(this).val(),null,false)" required>
										</select>
								    </div>
								 
                            </td>
                        </tr>
       
                        <tr class="odd">
                           <td style="text-align: right;">地区<span class="fill-must">*</span></td>
                            <td class="even">
		                            <div class="m-wrap span8 sheet-selectTwoBar">
										  <select class="form-control" id="areaid" name="areaid" required>
										</select>
								    </div>
								 
                            </td>
                            <td style="text-align: right;">地址<span class="fill-must">*</span></td>
                            <td class="center">
                                   <input   class="m-wrap span8" style="margin-top: 10px" type="text" id="address" name="address" required  " placeholder="请输入地址"/>
                            </td>
                        </tr>
   
                        <tr class="even">
                            <td style="text-align: right;">网点名称<span class="fill-must">*</span></td>
                            <td class="even">
                                   <input class="m-wrap span8" style="margin-top: 10px" type="text" id="name" name="name" required  placeholder="请输入网点名称"  data-msg-remote="网点名已存在" onkeyup="dataform.form();"/>
                            </td>
                           <td style="text-align: right;">通道数量<span class="fill-must">*</span></td>
                            <td class="center">
                                <input class="m-wrap span8" style="margin-top: 10px" type="text" id="channel_num" name="channel_num" required data-rule-digits="true" data-msg-digits="请输入一个整数"  placeholder="请输入通道数量"/>
                            </td>
                        </tr>
          
                        <tr class="odd">
                            <td style="text-align: right;">联系电话<span class="fill-must">*</span></td>
                            <td class="center">
                                <input class="m-wrap span8" style="margin-top: 10px" type="text" id="tel" name="tel" required   required data-rule-mobile="true" data-msg-mobile="请输入正确电话格式" placeholder="请输入联系电话"/>
                            </td>
                            <td style="text-align: right;">产权公司<span class="fill-must">*</span></td>
                            <td class="center">
                                <select id="proper_companyid" name="proper_companyid" class="m-wrap span8"   style="margin-top: 10px" required>
                                <option value="">===请选择===</option>
                                <#if companyList??>
	                                <#list companyList as clist> 
	                                    <option value="<#if clist.getKey()??>${clist.getKey()}</#if>"><#if clist.getValue()??>${clist.getValue()}</#if></option>
	                                </#list>
                                  </#if>
                                </select>
                            </td>
 
                        </tr>
           
                    
                        <tr class="even">
                             <td style="text-align: right;">开始时间<span class="fill-must">*</span></td>
                            <td class="even">
                                   <input class="m-wrap span8" style="margin-top: 10px" type="text" id="beginTime" name="beginTime"  onfocus="WdatePicker({ dateFmt: 'HH:mm:ss' })"    placeholder="请输入工作开始时间" />
                            </td>
                            <td style="text-align: right;">结束时间<span class="fill-must">*</span></td>
                            <td class="odd">
                                   <input class="m-wrap span8" style="margin-top: 10px" type="text" id="endTime" name="endTime"  onfocus="WdatePicker({ dateFmt: 'HH:mm:ss' })"      placeholder="请输入工作结束时间" />
                            </td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: right;">超级站<span class="fill-must">*</span></td>
                            <td class="even">
                                <div class="m-wrap span8"  style="margin-top: 10px" >
							        <label class="radio-inline">
									  <input type="radio" name="supersite"  value="0" checked="checked"> 否
									</label>
									<label class="radio-inline">
									  	  <input type="radio" name="supersite"  value="1"> 是
									</label>
							     </div>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    </br>
                    <div class="controls controls-row" style="text-align: right;">
                        <input   type="hidden" id="editId" name="id" />
                        <input type="button" value="提交"  class="btn green" onclick="submitFormdata()"/>
                        <input type="button" value="取消"   class="btn green" onclick="hidePopup()" />
                        <input type="reset"  style="display: none" > 
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<div id="changeStateDiv" class="row-fluid" style="position: absolute;visibility: hidden;overflow: hidden;padding: 1px;z-index: 100;background-color: #FFFFFF;">
		<div class="span12">
        <div class="portlet box green" style="margin: -1px;">
            <div class="portlet-title">
                <div class="caption"><i class="fa fa-edit"></i>修改状态</div>
                <a href="javascript:hideEditTable();" class="remove"></a>
            </div>
            
            <div class="portlet-body flip-scroll">
            	<form id="changeStatusform" action="" method="POST">
               
            	<table class="table-bordered table-striped table-condensed flip-content">
            		<tbody role="alert" aria-live="polite" aria-relevant="all">
            		
            		<tr class="even">
            			<td style="text-align: right;">状态</td>
            			<td class="even">
            			   <div style="margin-top: 10px" class="m-wrap span8">
	         					<label class="radio-inline">
								  <input type="radio" name="state"   value="1">运营中
								</label>
								<label class="radio-inline">
								  <input type="radio" name="state"    value="2"> 已关闭
								</label>
								<label class="radio-inline">
								  <input type="radio" name="state"    value="3"> 维修中
								</label>
							</div>
            			</td>
            		</tr>
            		</tbody>
            		</table>
            		<div class="controls controls-row" style="text-align: right;">
                        <input type="submit" value="保存" class="btn green"/>
                        <input type="button" value="取消" class="btn green" onclick="hidePopup()" />
                    </div>
            	</form>
            </div>
        </div>
        </div>
	</div>

<div class="page-container row-fluid">

<#include "bases/sidebar.ftl">
<#include "bases/navhead.ftl">

    <div class="page-content secMenu-content" id="loading">
     
        <div class="container-fluid">
 
            <div class="row-fluid">
                <div class="span12">
                    <div class="portlet box green">
                        <div class="portlet-title">
                            <div class="caption"><i class="fa fa-cogs"></i>换电站点列表</div>
                            <div class="tools">
                                <a href="javascript:window.location.reload()" class="reload"></a>
                            </div>                            
                        </div>
                        <div class="portlet-body flip-scroll">
                            <form id="searchform" action="${base}/electric_charging_site_manage" method="POST">
                               
                                <div class="controls controls-row">
                                    <label for="name">网点名称：</label>
                                    <input  name="name" type="text" class="form-control sheet-searchInput" id="name" value="<#if name??>${name}</#if>"/>
                                   
                                    <label for="name">网点状态：</label>
	                                <select id="state" name="state" class="form-control sheet-searchInput" style="margin-top: 10px">
	                                <option value="">===请选择===</option>
	                                <#if stateList??>
		                                <#list stateList as slist> 
		                                    <option value="<#if slist.getKey()??>${slist.getKey()}</#if>"  <#if state??><#if state=="${slist.getKey()}">selected="selected"</#if></#if>><#if slist.getValue()??>${slist.getValue()}</#if></option>
		                                </#list>
	                                  </#if>
	                                </select>

                                    <button type="submit" class="btn blue" onclick="searchButton()">搜索 </button>
                                
                                    <input  type="hidden" id="currentpage" name="page" value="0" />
                                    <input  type="hidden" id="postsortfield" name="sortfield" value="<#if sortfield??>${sortfield}</#if>" />
                             
                                </div>
                                <div class="controls controls-row" style="margin-top: 20px">
                                    <button id="sample_editable_1_new" type="button" class="btn green" onclick="showAddDiv()"><i class="fa fa-plus"></i>增加网点</button>
 
                                </div>
                                <table  class="table table-bordered table-hover table-striped table-condensed list-table">
                                    <thead class="flip-content">
                                    <tr>
                                          <th style="text-align: center;">ID</th>
								          <th style="text-align: center;">网点名称</th>
								          <th style="text-align: center;">通道数量</th>
								          <th style="text-align: center;">地区</th>
								          <th style="text-align: center;">地址</th>
								          <th style="text-align: center;">电话</th>
								          <th style="text-align: center;">工作时间</th>
								          <th style="text-align: center;" onclick="javascript:doTableSort('companyname')">产权公司</th>
								          <th style="text-align: center;">状态</th>
								          <th style="text-align: center;">超级站</th>
								          <th style="text-align: center;width: 200px">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <#list electric_charging_site_list as ecs>
                                    <tr>
                                        <td style="text-align: center;"><#if ecs.getPinyin_name()??>${ecs.getPinyin_name()}</#if></td>
                                        <td style="text-align: center;"><#if ecs.getName()??>${ecs.getName()}</#if></td>
                                        <td style="text-align: center;"><#if ecs.getChannel_num()??>${ecs.getChannel_num()}</#if></td>
                                        <td style="text-align: center;"><#if ecs.getAreaName()??>${ecs.getAreaName()}</#if></td>
                                        <td style="text-align: center;"><#if ecs.getAddress()??>${ecs.getAddress()}</#if></td>
                                        <td style="text-align: center;"><#if ecs.getTel()??>${ecs.getTel()}</#if></td>
                                        <td style="text-align: center;">
                                          <#if ecs.getBeginTime()??>${ecs.getBeginTime()}</#if>
                                           -
                                          <#if ecs.getEndTime()??>${ecs.getEndTime()}</#if>
                                        </td>
                                        <td style="text-align: center;"><#if ecs.getProperCompanyName()??>${ecs.getProperCompanyName()}</#if></td>
                                        <td style="text-align: center;"><#if ecs.getStateName()??>${ecs.getStateName()}</#if></td>
                                        <td style="text-align: center;"><#if ecs.getSupersiteName()??>${ecs.getSupersiteName()}</#if></td>
    
                                        <td style="text-align: center;">
                                         
                                         	<a id="editButton" onclick="showEditDiv('${ecs.getId()}');">编辑</a>
                                            
                                            <a onclick="changeState('<#if ecs.getState()??>${ecs.getState()}</#if>',${ecs.getId()});">修改状态</a>
                                      
                                        </td>
                                    </tr>
                                    </#list>
                                    </tbody>
                                </table>
                                <div class="controls controls-row">
                                    <div id="Pagination" class="pagination"></div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
  </div>
 
</body>
</html>

 
